package com.improve.frame.common.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.improve.frame.common.annotation.Desensitized;
import com.improve.frame.common.constant.RegexpConstant;
import com.improve.frame.common.enums.SensitiveType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.List;

/**
 * @Description
 *      用户
 * @Author wzxing918
 * @Date 2021-03-31
 * @Version 1.0.0
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_user")
@ApiModel(description = "用户")
public class SysUser extends BaseEntity {
    /**
     * 部门ID
     */
    @ApiModelProperty(value = "部门ID", name = "deptId",example = "0")
    private Long deptId;
    /**
     * 用户账号
     */
    @NotBlank(message = "用户账号不能为空")
    @ApiModelProperty(value = "用户账号", name = "username")
    private String username;
    /**
     * 用户昵称
     */
    @ApiModelProperty(value = "用户昵称", name = "nickName")
    private String nickName;
    /**
     * 用户类型（00系统用户）
     */
    @ApiModelProperty(value = "用户类型（00系统用户）", name = "userType")
    private String userType;
    /**
     * 用户邮箱
     */
    @ApiModelProperty(value = "用户邮箱", name = "email")
    private String email;
    /**
     * 手机号码
     */
    @NotBlank(message = "手机号码不能为空")
    @Pattern(regexp = RegexpConstant.MOBILE, message = "手机号格式错误")
    @ApiModelProperty(value = "手机号码", name = "mobile")
    @Desensitized(type = SensitiveType.MOBILE)
    private String mobile;
    /**
     * 用户性别（1男 2女 3未知）
     */
    @ApiModelProperty(value = "用户性别（1男 2女 2未知）", name = "sex",example = "0")
    private Integer sex;
    /**
     * 头像地址
     */
    @ApiModelProperty(value = "头像地址", name = "avatar")
    private String avatar;
    /**
     * 密码
     */
    @ApiModelProperty(value = "密码", name = "password")
    @Pattern(regexp = RegexpConstant.PASSWORD_SPEC,message = "密码必须包含大小写字母、数字、特殊字符的组合")
    private String password;
    /**
     * 帐号状态（1正常 1停用）
     */
    @ApiModelProperty(value = "帐号状态（1正常 1停用）", name = "status",example = "0")
    private Integer status;
    /**
     * 删除标志（1代表存在 2代表删除）
     */
    @TableLogic
    @ApiModelProperty(value = "删除标志（1代表存在 2代表删除）", name = "delFlag",example = "0")
    private Integer delFlag;
    /**
     * 最后登陆IP
     */
    @ApiModelProperty(value = "最后登陆IP", name = "loginIp")
    private String loginIp;
    /**
     * 最后登陆时间
     */
    @ApiModelProperty(value = "最后登陆时间", name = "loginDate")
    private Date loginDate;
    /**
     * 备注
     */
    @ApiModelProperty(value = "备注", name = "remark")
    private String remark;

    /**
     * OpenId
     */
    @ApiModelProperty(value = "OpenId", name = "OpenId")
    private String openId;

    /** 部门对象 */
    @TableField(exist = false)
    private SysDept dept;

    /** 角色对象 */
    @TableField(exist = false)
    private List<SysRole> roles;

    /** 角色组 */
    @TableField(exist = false)
    private Long[] roleIds;

    /** 岗位组 */
    @TableField(exist = false)
    private Long[] postIds;

    public SysUser(){

    }

    public SysUser(Long id){
        this.id = id;
    }

    public boolean isAdmin()
    {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(Long id)
    {
        return id != null && 1L == id;
    }
}
